# 邮件类
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText


class EmailTool:

    def __init__(self,email,pwd):
        # 发送者邮箱
        # self.from_email = "1926299516@qq.com"
        self.from_email = email
        # 发送者邮箱smtp密钥
        # self.pwd = "cvqbpjukqwwpbjfc"
        self.pwd = pwd

    # 邮件发送方法  发送激活链接或者随机激活码
    def sendmail(self, tomail, code):
        # 设置邮件主体
        msg = MIMEMultipart()
        # 设置标题
        msg["Subject"] = "OA"
        # 发件人
        msg["From"] = self.from_email
        # 收件人
        msg["To"] = tomail

        # 设置邮件文本
        part = MIMEText("发送内容是：%s" % code, "html", "utf-8")
        msg.attach(part)

        # 登录qq邮箱
        s = smtplib.SMTP_SSL("smtp.qq.com", 465)
        s.login(self.from_email, self.pwd)
        # 调用发送方法
        s.sendmail(self.from_email, tomail, msg.as_string())
        # 关闭邮件链接
        s.close()